import hljs from "highlight.js"

export function createTableCode(arrayData: any) {
    for (const data of arrayData) {
        if (data.type == "array") {
            let fra = ""
            for (const subData of data.sub) {
                fra += `  <el-table-column prop="${subData.name}" label="${subData.description.trim()}" />\n`
            }
            let code = `<el-table :data="tableData" style="width: 100%">\n${fra}</el-table>`

            return hljs.highlightAuto(code, ["html"]).value
        }
    }
    return ""
}

export function createRulesCode(arrayData: any) {
    let fra = ""
    for (const subData of arrayData) {
        if(subData.required){
            fra += `  ${subData.name}: [ \n\t{required: ${subData.required}, type: "${subData.type}", message: "请输入${subData.description.trim()}", trigger: "change"}, \n  ], \n`
        }else {
            fra += `  ${subData.name}: [ \n\t{type: "${subData.type}", message: "请输入${subData.description.trim()}", trigger: "change"}, \n  ], \n`
        }
    }
    let code = `const rules = {\n${fra}}`

    return hljs.highlightAuto(code, ["typescript"]).value
}